using System;
using System.Windows.Controls;
using System.Windows.Input;
using SalesPoint.Commands;
using Xtensive.Orm;

namespace SalesPoint.ViewModels
{
  public abstract class WorkspaceViewModel : ViewModelBase
  {
    private DelegateCommand closeCommand;

    public string DisplayName { get; private set; }

    public Control View { get; set; }

    public event EventHandler<EventArgs> Close;

    public ICommand CloseCommand
    {
      get
      {
        if (closeCommand != null)
          return closeCommand;

        closeCommand = new DelegateCommand(ExecuteClose);
        return closeCommand;
      }
    }

    private void InvokeClose(EventArgs e)
    {
      var handler = Close;
      if (handler != null) handler(this, e);
    }

    private void ExecuteClose()
    {
      InvokeClose(new EventArgs());
    }

    protected WorkspaceViewModel(Session session, string displayName)
      : base(session)
    {
      DisplayName = displayName;
    }
  }
}
